package com.petshop.controller;

import com.petshop.dto.QueryPostDTO;
import com.petshop.pojo.Posts;
import com.petshop.service.PostsService;
import com.petshop.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("post")
@CrossOrigin
public class PostsController {

    @Resource
    private PostsService postsService;

    /*
    增加一条帖子
     */
    @PostMapping("insertPost")
    public Result insertPost(@RequestBody Posts posts  ) {
        Result result = postsService.insertPost(posts);
        return result;
    }

    /*
    删除一条帖子
     */
    @GetMapping("deletePost")
    public Result deletePost(Integer postId) {
        Result result = postsService.deletePost(postId);
        return result;
    }

    /*
    修改一条帖子
     */
    @PostMapping("updatePost")
    public Result updatePost(@RequestBody Posts posts) {
        Result result = postsService.updatePost(posts);
        return result;
    }

    /*
    点赞功能
     */
    @PostMapping("/like/{id}")
    public Result like(@PathVariable Integer postId) {
        Result result = postsService.likePost(postId);
        return result;
    }

    /*
    根据帖子id查询帖子
     */
    @GetMapping("queryPostById")
    public Result queryPostById(Integer postId) {
        Result result = postsService.queryPostById(postId);
        return result;
    }

    /*
    获取帖子列表
     */
    @PostMapping("getPostList")
    public Result getPostList(@RequestBody QueryPostDTO queryPostDTO) {
        Result result = postsService.getPostList(queryPostDTO);
        return result;
    }

    /*
    获取当前用户的帖子
     */


    /*
    仅查询第一页帖子
     */
    @PostMapping("getFirstPost")
    public Result getFirstPost(@RequestBody QueryPostDTO queryPostDTO) {
        Result result = postsService.getFirstPost(queryPostDTO);
        return result;
    }

    /*
    获取帖子详情，点赞数，评论数
     */
    @GetMapping("getPostDetail")
    public Result getPostDetail(Integer postId, @RequestHeader("Authorization") String token) {
        Result result = postsService.getPostDetail(postId, token);
        return result;
    }

    /*
    滚动查询关注的人的帖子
     */
    @GetMapping("/getFollowPost")
    public Result getFollowPost(@RequestParam("lastId")Long max,
                                @RequestParam(value = "offset",defaultValue = "0") Integer offset) {
        Result result = postsService.queryFollowPost(max,offset);
        return result;
    }
}
